# Maintainer: David Runge <dvzrv@archlinux.org>

pkgname=virt-firmware
pkgver=23.10
pkgrel=1
pkgdesc="Collection of tools for edk2 firmware images"
arch=(any)
url="https://gitlab.com/kraxel/virt-firmware"
license=(GPL-2.0-or-later)
depends=(
  python
  python-crc32c  # undeclared runtime dependency: https://gitlab.com/kraxel/virt-firmware/-/issues/4
  python-cryptography
  python-pefile
  python-setuptools
)
makedepends=(
  python-build
  python-installer
  python-wheel
)
checkdepends=(python-pytest)
source=($url/-/archive/v$pkgver/$pkgname-v$pkgver.tar.gz)
sha512sums=('e23824a429b337166891d3d08aac6f99394d554e9631e7c23a95e24b8b9ad8d8addb8a6cdb59029776679f1fc4bdbb2608dd0dc2a1edaa4be634adf1f3dd9cd8')
b2sums=('09cd5f19a860427f63256e8eb3445cce19e079f38f64b9cb1f4187acb9d4f8fab3f4d5862c22580ec457b615e245690fce91748e76d84e44156e0b71543a71cd')

build() {
  cd $pkgname-v$pkgver
  python -m build --wheel --no-isolation
}

check() {
  local _site_packages=$(python -c "import site; print(site.getsitepackages()[0])")

  cd $pkgname-v$pkgver
  python -m installer --destdir=test_dir dist/*.whl
  export PYTHONPATH="test_dir/$_site_packages:$PYTHONPATH"

  pytest -vv tests/tests.py
}

package() {
  cd $pkgname-v$pkgver
  python -m installer --destdir="$pkgdir" dist/*.whl
  install -vDm 644 man/virt-*.1 -t "$pkgdir/usr/share/man/man1/"
  install -vDm 644 README.md -t "$pkgdir/usr/share/doc/$pkgname/"
}
